﻿//import csbufparser = require("./csbufparser");
import {csbufparser} from "./csbufparser";
import * as ptl from "./ptl/protocol"

class Greeter {
    element: HTMLElement;
    span: HTMLElement;
    timerToken: number;

    constructor(element: HTMLElement) {
        this.element = element;
        this.element.innerHTML += "The time is: ";
        this.span = document.createElement('span');
        this.element.appendChild(this.span);
        this.span.innerText = new Date().toUTCString();
    }

    start() {
        this.timerToken = setInterval(() => this.span.innerHTML = new Date().toUTCString(), 500);

    }

    stop() {
        clearTimeout(this.timerToken);
    }
}

window.onload = () => {
    var el = document.getElementById('content');
    var greeter = new Greeter(el);
    greeter.start();
};

function cmp(a, b) {
    if (a != b) {
        alert(b)
    }
}

let t2 = new ptl.Resp1101();
t2.accoutId = "aaaa"
t2.info.playerId = "1314"
t2.info.name = ""
t2.info.money = 1
t2.token = "eeeeeeeeeeeeeeeeeeeee"
let t = new csbufparser()
t2.Marshal(t)
t.cursor = 0
let tt = ptl.getProtocol(1101, 2);

let t1 = new tt();
t1.Unmarshal(t)
alert(t1.token)
cmp(t2.accoutId, t1.accoutId)
cmp(t2.info.playerId, t1.info.playerId)
cmp(t2.url, t1.url)
cmp(t2.token, t1.token)
alert(t1.info.playerId)


//var p = new csbufparser()
//p.setBool(true, 1)
//p.setUint32(500000, 2)
//p.setInt64(-200000, 3)
//p.setString("abc", 4);
//p.setArray(2, 5);
//p.setFloat(1.223, 0)
//p.setDouble(2.334, 0)
//p.setMessage(6)
//p.setBool(true, 1)
//p.setUint8(10, 10)
//p.endSetMessage()
//p.setUint8(11, 10)
//var p2 = new csbufparser()
//var s = p.getData()
////alert(s.length)
////for (var i = 0; i < s.length; i++) {
////    //alert(String.fromCharCode(s.charCodeAt(i)));
////    alert(s.charCodeAt(i));
////}
//p2.setData(s)
//alert(p2.getBool(1))
//alert(p2.getUint32(2))
//alert(p2.getInt64(3))
//alert(p2.getString(4))
//alert(p2.getArray(5))
//alert(p2.getFloat(0))
//alert(p2.getDouble(0))
//p2.getMessage(6)
//alert(p2.getBool(1))
//alert(p2.getUint8(10))
//p2.endGetMessage()
//alert(p2.getUint8(10))

alert("end")
